<?php
/**
 * Created by PhpStorm.
 * User: pc
 * Date: 2019/8/6
 * Time: 2:06
 */

namespace app\admin\model;


class ApprovalDepartment extends Base
{
    /**
     * 获取列表
     * $t : 1获取列表 2导出
     */
    public function getList($t,$map,$query = [])
    {
        if($t == 1) {
            $list = $this->where($map)->order('apply_time desc')->paginate(10,false,['query' => $query]);
        }else {
            $list = $this->where($map)->order('apply_time desc')->select();
        }
        foreach ($list as $key => $value) {
            $status = [0 => "待审批", 1 => "审批通过", 2=> "审批不通过", 3=>"进行中"];
            $value['status_text'] = $status[$value['status']];
            $user = $this->getUser($value['apply_user']);
            $value['apply_name'] = $user ? $user['name'] : "无该用户信息";
            $value['apply_time_text'] = date("Y-m-d H:i",$value['apply_time']);
            $depart1 = $this->getDepartment($value['assign_department']);
            $depart2 = $this->getDepartment($value['handle_department']);
            $value['assign_department_name'] = !empty($depart1) ? $depart1['name'] : '--';
            $value['handle_department_name'] = !empty($depart2) ? $depart2['name'] : '--';
            $value['assign_time_text'] = date("Y-m-d H:i",$value['assign_time']);
            $value['plan_time_text'] = date("Y-m-d H:i",$value['plan_time']);
        }
        return $list;

    }
}